import 'package:boss/models/book_info_list_data.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flustars/flustars.dart' as flustars;

class BookingHistoryItem extends StatelessWidget {
  final BookInfo data;

  const BookingHistoryItem(this.data);

  @override
  Widget build(BuildContext context) {
    return ShadowRadiusCard(
      margin: EdgeInsets.only(bottom: 30.w),
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: Column(
        children: <Widget>[
          Container(
            height: 82.w,
            child: Row(
              children: <Widget>[
                Expanded(
                  flex: 3,
                  child: Row(
                    children: <Widget>[
                      Container(
                        width: 100.w,
                        child: Text(
                          BookInfo.statusMap[data.status],
                          style: TextStyleConstant().blue_28,
                          textAlign: TextAlign.left,
                        ),
                      ),
                      Container(
                        child: Text(
                          '预订时间：${flustars.DateUtil.formatDateStr(data.ctime, format: flustars.DateFormats.y_mo_d_h_m)}',
                          style: TextStyleConstant().normal_3_24,
                        ),
                      ),
                    ],
                    mainAxisAlignment: MainAxisAlignment.start,
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Text(
                    '接单人：${data.waiterName}',
                    style: TextStyleConstant().normal_2_24,
                    maxLines: 1,
                  ),
                ),
              ],
            ),
          ),
          CustomDivider(),
          Container(
            padding: EdgeInsets.symmetric(vertical: 20.w),
            child: Column(
              children: <Widget>[
                buildRow('预订人', data.customerName, '桌数', '${data.tableList.length}桌'),
                buildRow('手    机', data.phone, '人数', '${data.personNum}人'),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget buildRow(String firstTitle, String firstValue, String secondTitle, String secondValue) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 10.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          buildText(firstTitle, firstValue, flex: 3),
          buildText(secondTitle, secondValue, textAlign: TextAlign.start),
        ],
      ),
    );
  }

  Widget buildText(String title, String value, {TextAlign textAlign = TextAlign.start, int flex = 1}) {
    return Expanded(
      flex: flex,
      child: RichText(
        textAlign: textAlign,
        text: TextSpan(text: '$title：', style: TextStyleConstant().normal_2_28, children: [
          TextSpan(
            text: value,
            style: TextStyleConstant().normal_1_28,
          ),
        ]),
      ),
    );
  }
}
